﻿from google.appengine.ext import db

DEFAULT_LANG = 'ru'

class TranslationsXmlContent(db.Model):
	name = db.StringProperty(required=True)
	content = db.TextProperty(required=True)
	description = db.StringProperty()


g_categories = [u"Антикварная вещица", u"Естонский товар", u"Грузинский товар"]
from google.appengine.ext.db  import Key
class Product(db.Model):
	name = db.StringProperty(required=True)
	description = db.StringProperty()
	price = db.FloatProperty()
	date = db.DateTimeProperty(auto_now_add=True)
	rating = db.RatingProperty()
	count = db.IntegerProperty()
	origin = db.StringProperty(choices=set(g_categories))#db.ReferenceProperty(ItemCategory)
	image_path = db.StringProperty()
	image_alt = db.StringProperty()
	tags = db.StringListProperty()
	translation_labels = {}
	
	
	def translate(self, labelId):
		labelId_int = int(labelId)	
		trans_key = 'loc_' + str(1000 + labelId_int);
		if trans_key in self.translation_labels.keys():				
			return self.translation_labels[trans_key]
		else:
			return "[[" + str(labelId) + "]]"

	def name_loc(self):
		return self.translate(self.name)
	
	def desc_loc(self):
		return self.translate(self.description)
	
	def alt_loc(self):
		return self.translate(self.image_alt)

	def set_translation_labels(self, translation_labels):
		self.translation_labels = translation_labels
		return self;

import datetime;
import random;


def get_product(name_lbl, desc_lbl, image_alt_lbl, image, price, rating, tags=[u'товар'], origin_id=2):
	return Product.get_or_insert('name:'+name_lbl, name= name_lbl, description= desc_lbl, image_alt = image_alt_lbl, 
								 image_path = image, price = price,	
								 rating = rating, tags=tags, 
								 date = datetime.datetime.now(), origin=g_categories[origin_id], count = random.randrange(0, 10))




TEST_TOP_PRODUCTS = [
				get_product('1', '2', '3', 'vilochka.png', 50.00, 5, [u'vilochka', u'вилочка'] ),
				get_product('5', '6', '7', 'cool_boots.png', 10.15, 5, [u'туфли', u'охуенные'] ),
				get_product('11', '12', '13', 'velo.png', 20.00, 4, [u'вело', u'танк'] ),
				get_product('14', '15', '16', 'jeep_sion.png', 999.99, 4, [u'джип', u'авто'] ),
				]
				


def flush_model(modelClass):
	for entity in modelClass.all():
		entity.delete()
